/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.passport.service.plugins  
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.passport.entity.SynInfo;
import com.apache.passport.manager.SynInfoManager;

/**
 * description:  根据系统名称查询外部系统同步参数
 * @author Hou Dayu 创建时间：2014-12-26  
 * @Copyright(c)2014:
 */
public class SysEnameQueryPlugin implements PluginConnector {
	protected IDao synInfoDao;
	private SynInfoManager synInfoManager;

	public void setSynInfoDao(IDao synInfoDao) {
		this.synInfoDao = synInfoDao;
	}

	public void setSynInfoManager(SynInfoManager synInfoManager) {
		this.synInfoManager = synInfoManager;
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo paramsvo) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		String sysEname = (String) paramsvo.getParams("sysEname");
		if (Validator.isEmpty(sysEname)) {
			result.setEntity("F");
			result.setMessage("系统名称不能为空");
			return result;
		}

		SynInfo synInfo = (SynInfo) getSysInfoByEname(sysEname);
		if (Validator.isEmpty(synInfo)) {
			result.setEntity("F");
			result.setMessage("未查询到此系统");
			return result;
		}
		result.setEntity("T");
		result.setEntity(synInfo);
		result.setMessage("系统参数查询成功");
		return result;
	}

	public Object getSysInfoByEname(String sysEname) {
		String sql = synInfoDao.getSql(3);
		MethodParam param = new MethodParam("BySysEname", "", sql, "com.apache.passport.entity.SynInfo");
		param.setParams("sysEname", sysEname);
		return synInfoDao.selectSingle(param);
	}

}
